/*
** my_str_to_wordtab2.c for 42sh in /home/lingla_j/work/projet/42sh/Ju
** 
** Made by julien linglain
** Login   <lingla_j@epitech.net>
** 
** Started on  Fri Apr  6 11:43:11 2012 julien linglain
** Last update Fri Apr  6 11:46:26 2012 julien linglain
*/

#include        <stdio.h>
#include        <unistd.h>
#include        <stdlib.h>
#include        <sys/types.h>
#include        "mysh.h"

int	countword3(char *s, int i, int j)
{
  i++;
  while (s[i] != '"' && s[i] != '\0')
    i++;
  i++;
  return (i);
}

int	countword2(char *s)
{
  int	i;
  int	j;
  int	wd;

  i = 0;
  wd = 0;
  while (s[i] != '\0')
    {
      while (s[i] != '\0' && is_space(s[i]))
        i++;
      j = i;
      if (s[j] == '"')
        i =       countword3(s, i, j);
      else
        {
          while (s[i] != '\0' && !is_space(s[i]))
            i++;
        }
      if ((i - j) != 0)
        wd++;
    }
  return (wd + 1);
}

int	countword(char *s)
{
  int	i;
  int	j;
  int	wd;

  i = 0;
  wd = 0;
  while (s[i] != '\0')
    {
      while (s[i] != '\0' && is_space(s[i]))
        i++;
      j = i;
      while (s[i] != '\0' && !is_space(s[i]))
        i++;
      if ((i - j) != 0)
        wd++;
    }
  return (wd + 1);
}

void	show_tab(char **tab, int wd)
{
  int	i;

  i = 0;
  while (tab[i] != '\0')
    {
      my_putstr(tab[i]);
      if (i < (wd - 1))
        my_putchar('\n');
      i++;
    }
}
